﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
namespace EmployeeCheckIn
{
    public class InSertData

    {

        public void Insertss(EmpEntity emp)
        {
            
            string sqltext = @"insert into EMPLOYEE 
                           (emp_ID
                          ,[EMP_CODE]
                          ,[EMP_PREFIX]
                          ,[EMP_FIRSTNAME]
                          ,[EMP_LASTNAME]
                          ,[EMP_POSITION]
                          ,[EMP_START_DATE]
                          ,[EMP_BIRTH_DATE]
                          ,[EMP_ID_CARD]
                          ,[EMP_ADDRESS]
                          ,[EMP_PROVINCE_CODE]
                          ,[EMP_POST_CODE]
                          ,[EMP_PHONE])
                           values (@emp_ID,@emp_code,@emp_prefix,@emp_firstname,@emp_lastname,@emp_position
                                   ,@emp_start_date,@emp_birth_date,@emp_id_card,@emp_address,@emp_province_code,@emp_post_code,@emp_phone)";
            SqlCommand sqlcomm = new SqlCommand();
            SqlConnection sqlconn = new SqlConnection("Server=NUEK-PC\\SA;Database=DB_CHECK_EMPLOYEE;User Id=sa;Password=1234qwer;");
            sqlcomm.Connection = sqlconn;
            sqlcomm.CommandType = System.Data.CommandType.Text;
            sqlcomm.CommandText = sqltext;
            sqlcomm.Parameters.AddWithValue("@emp_ID", emp.ID);
            sqlcomm.Parameters.AddWithValue("@emp_code",emp.EmpId);
            sqlcomm.Parameters.AddWithValue("@emp_prefix", emp.Prefix);
            sqlcomm.Parameters.AddWithValue("@emp_firstname", emp.FirstName);
            sqlcomm.Parameters.AddWithValue("@emp_lastname", emp.LastName);
            sqlcomm.Parameters.AddWithValue("@emp_position", emp.Position);
            sqlcomm.Parameters.AddWithValue("@emp_start_date", emp.DateStart);
            sqlcomm.Parameters.AddWithValue("@emp_birth_date", emp.DateBirth);
            sqlcomm.Parameters.AddWithValue("@emp_id_card", emp.CardID);
            sqlcomm.Parameters.AddWithValue("@emp_address", emp.Address);
            sqlcomm.Parameters.AddWithValue("@emp_province_code", emp.City);
            sqlcomm.Parameters.AddWithValue("@emp_post_code", emp.PostID);
            sqlcomm.Parameters.AddWithValue("@emp_phone", emp.Phone);
            try
            {
                sqlcomm.Connection.Open();
                sqlcomm.ExecuteNonQuery();
            }
            catch (Exception)
            {

                sqlcomm.Connection.Close();
                sqlcomm.Connection.Dispose();
            }
            sqlcomm.Connection.Close();
            sqlcomm.Connection.Dispose();
            
        }
        
    }
}